<%@include file="/WEB-INF/pages/commons/commons.jsp" %>

<stripes:layout-definition>
    <stripes:layout-render name="${_themePath}/basic-layout.jsp">
        <stripes:layout-component name="_head">
            <c:out value="${_head}" escapeXml="false"/>
            <!-- Radoex render engine result's styling -->
            <link rel="stylesheet" type="text/css" href="<c:url value='${_themePath}/styles/radeox.css'/>"/>

            <%--
            <!-- Sam Skin CSS for TabView -->
            <link rel="stylesheet" type="text/css" href="<c:url value='/yui/build/tabview/assets/skins/sam/tabview.css'/>">

            <!-- JavaScript Dependencies for Tabview: -->
            <script type="text/javascript" src="<c:url value='/yui/build/yahoo-dom-event/yahoo-dom-event.js'/>"></script>
            <script type="text/javascript" src="<c:url value='/yui/build/element/element-min.js'/>"></script>

            <!-- OPTIONAL: Connection (required for dynamic loading of data) -->
            <script type="text/javascript" src="<c:url value='/yui/build/connection/connection-min.js'/>"></script>

            <!-- Source file for TabView -->
            <script type="text/javascript" src="<c:url value='/yui/build/tabview/tabview-min.js'/>"></script>
            --%>

            <!-- drop down menu -->
            <script type="text/javascript">
            // === spaceHeaderMenu
                YAHOO.util.Event.onContentReady("pageHeaderMenu", function() {
                    var manageHeaderMenu = new YAHOO.widget.Button("pageHeaderMenuButton",
                                            { type: "menu", menu: "pageHeaderMenuButtonSelect" });
                    //	"click" event listener for the second Button's Menu instance
                    var onMenuClick = function (p_sType, p_aArgs) {
                        var oEvent = p_aArgs[0];	//	DOM event
                        var oMenuItem = p_aArgs[1];	//	MenuItem instance that was the
                                                    //	target of the event
                        if (oMenuItem) {
                            if ('0' == oMenuItem.value) {   // Add Page
                                <stripes:url var="url" beanclass="foo.bar.wiki.web.action.page.AddPageActionBean" event="view">
                                        <stripes:param name="page" value=""/>
                                        <stripes:param name="page.spaceId" value="${actionBean.page.space.id}"/>
                                </stripes:url>
                                document.location.href = '${url}';
                            }
                            else if ('1' == oMenuItem.value) { // remove space
                                <stripes:url var="url" beanclass="foo.bar.wiki.web.action.space.RemoveSpaceActionBean" event="remove">
                                    <stripes:param name="space" value="${actionBean.page.space.id}"/>
                                </stripes:url>
                                document.location.href='${url}';
                            }
                            else if ('2' == oMenuItem.value) { // edit space
                                <stripes:url var="url" beanclass="foo.bar.wiki.web.action.space.EditSpaceActionBean" event="view">
                                    <stripes:param name="space" value="${actionBean.page.space.id}"/>
                                </stripes:url>
                                document.location.href='${url}';
                            }
                            else if ('3' == oMenuItem.value) { // show space as wiki page
                                <stripes:url var="url" beanclass="foo.bar.wiki.web.action.space.SpaceActionBean" event="view">
                                    <stripes:param name="space" value="${actionBean.page.space.id}"/>
                                </stripes:url>
                                document.location.href='${url}';
                            }
                            else if ('4' == oMenuItem.value) { // delete this page
                               <stripes:url var="url" beanclass="foo.bar.wiki.web.action.page.RemovePageActionBean" event="remove_backToWikiSpace">
                                    <stripes:param name="page" value="${actionBean.page.id}"/>      
                               </stripes:url>
                                document.location.href='${url}';
                            }
                            else if ('5' == oMenuItem.value) { // manage this page
                                <stripes:url var="url" beanclass="foo.bar.wiki.web.action.page.EditPageActionBean" event="view">
                                    <stripes:param name="page" value="${actionBean.page.id}"/>
                                </stripes:url>
                                document.location.href='${url}';
                            }
                            else if ('6' == oMenuItem.value) { // add resource
                                <stripes:url var="url" beanclass="foo.bar.wiki.web.action.resource.AddResourceActionBean" event="view">
                                    <stripes:param name="page" value="${actionBean.page.id}"/>
                                    <stripes:param name="resource" value=""/>
                                </stripes:url>
                                document.location.href='${url}';
                            }
                            else if ('7' == oMenuItem.value) { // mark as default page
                                <stripes:url var="url" beanclass="foo.bar.wiki.web.action.page.MarkPageAsSpaceDefaultActionBean" event="save_backToWikiPage">
                                    <stripes:param name="page" value="${actionBean.page.id}"/>
                                </stripes:url>
                                document.location.href='${url}';
                            }
                            else if ('8' == oMenuItem.value) { // add to favourite
                                <stripes:url var="url" beanclass="foo.bar.wiki.web.action.page.AddToFavouriteActionBean" event="save">
                                    <stripes:param name="page" value="${actionBean.page.id}"/>
                                </stripes:url>
                                document.location.href='${url}';
                            }
                            else if ('9' == oMenuItem.value) { // atom 1.0
                                <stripes:url var="url" beanclass="foo.bar.wiki.web.action.general.PageFeedsActionBean" event="view">
                                    <stripes:param name="page" value="${actionBean.page.id}"/>
                                    <stripes:param name="feedType" value="atom_1_0" />
                                </stripes:url>
                                document.location.href='${url}';
                            }
                            else if ('10' == oMenuItem.value) { // rss 2.0
                                <stripes:url var="url" beanclass="foo.bar.wiki.web.action.general.PageFeedsActionBean" event="view">
                                    <stripes:param name="page" value="${actionBean.page.id}"/>
                                    <stripes:param name="feedType" value="rss_2_0" />
                                </stripes:url>
                                document.location.href='${url}';
                            }
                            else {
                                alert('unrecognized menu option');
                            }
                        }
                    };
                    //	Add a "click" event listener for the Button's Menu
                    manageHeaderMenu.getMenu().subscribe("click", onMenuClick);
                });
            </script>


            <!-- tabs -->
            <script type="text/javascript">
            YAHOO.util.Event.onContentReady("tabs", function() {
                
                var myTabs = new YAHOO.widget.TabView("tabs");
                var tab0 = myTabs.getTab(0); // view
                var tab1 = myTabs.getTab(1); // edit wiki syntax
                var tab2 = myTabs.getTab(2); // preview
                var tab3 = myTabs.getTab(3); // resources
                var tab4 = myTabs.getTab(4); // Wiki Syntax
                var tab5 = myTabs.getTab(5); // add resource

                

                tab0.on('click', function(e){ // when 'view' tab is clicked
                });
                tab1.on('click', function(e){ // when 'edit' tab is clicked
                });
                tab2.on('click', function(e){ // when 'edit' tab is clicked
                    tab2.set('content', 'Loading ...');
                    //$("#wikiMarkup").text(); -> jQuery seems to be caching this stuff, ouch :(
                    var wikiMarkupContent = document.getElementById("wikiMarkup").value;
                    var pageId = $("#pageId").val();
                    $.post(
                            "<stripes:url beanclass='foo.bar.wiki.web.action.page.PageActionBean' event='renderWikiMarkup'/>",
                            {
                                page: pageId,
                                wikiMarkup: wikiMarkupContent,
                                renderWikiMarkup: ''
                            },
                            function(data){
                                tab2.set('content', data);
                            });
                });

                <c:if test="${not empty param['tab']}">
                    myTabs.selectTab(${param['tab']});
                </c:if>
            });
            </script>
        </stripes:layout-component>

        <stripes:layout-component name="_topNav">
            <H1>Page [${actionBean.page.fullPath}]</H1>
            <UL class="gc-topnav-tabs">
                <LI>&nbsp;
                    <span id="pageHeaderMenu">
                        <input type="button" id="pageHeaderMenuButton" value="Options"/>
                        <select id="pageHeaderMenuButtonSelect">
                            <jsecurity:hasPermission name="space:addPage:${actionBean.page.space.id}">
                                <option value="0">Add Page</option>
                                <option value="x">&nbsp;</option>
                            </jsecurity:hasPermission>
                            <jsecurity:hasPermission name="space.removeSpace:${actionBean.page.space.id}">
                                <option value="1">Delete Space</option>
                                <option value="x">&nbsp;</option>
                            </jsecurity:hasPermission>
                            <foobarwiki:hasAnyPermissions name="space:editSpace:${actionBean.page.space.id}|space:viewSpace:${actionBean.page.space.id}">
                                <option value="2">Manage Space</option>
                                <option value="x">&nbsp;</option>
                            </foobarwiki:hasAnyPermissions>
                            <jsecurity:hasPermission name="space:viewSpaceAsWiki:${actionBean.page.space.id}">
                                <option value="3">Show Space AS Wiki Page</option>
                                <option value="x">&nbsp;</option>
                            </jsecurity:hasPermission>
                            <jsecurity:hasPermission name="space:removePage:${actionBean.page.space.id}">
                                <option value="4">Delete This Page</option>
                                <option value="x">&nbsp;</option>
                            </jsecurity:hasPermission>
                            <foobarwiki:hasAnyPermissions name="space:editPage:${actionBean.page.space.id}|space:viewPage:${actionBean.page.space.id}">
                                <option value="5">Manage This Page</option>
                                <option value="x">&nbsp;</option>
                            </foobarwiki:hasAnyPermissions>
                            <jsecurity:hasPermission name="space:editPage:${actionBean.page.space.id}">
                                <option value="6">Add Resource To This Page</option>
                                <option value="x">&nbsp;</option>
                            </jsecurity:hasPermission>
                            <jsecurity:hasPermission name="space:editSpace:${actionBean.page.space.id}">
                                <option value="7">Mark As Default Page</option>
                                <option value="x">&nbsp;</option>
                            </jsecurity:hasPermission>
                            <jsecurity:authenticated>
                                <option value="8">Add To Favourite</option>
                                <option value="x">&nbsp;</option>
                            </jsecurity:authenticated>
                            <jsecurity:hasPermission name="space:viewSpace:${actionBean.page.space.id}">
                                <option value="9">ATOM 1.0</option>
                                <option value="x">&nbsp;</option>
                                <option value="10">RSS 2.0</option>
                            </jsecurity:hasPermission>
                        </select>
                    </span>
                </LI>
            </UL>
        </stripes:layout-component>

        <stripes:layout-component name="_content">
            <stripes:messages />
            <br/>
            <div id="tabs" class="yui-navset">
                <ul class="yui-nav">
                    <li class="selected"><a href="#tab1"><em>View</em></a></li>
                    <li><a href="#tab2"><em>Edit</em></a></li>
                    <li><a href="#tab3"><em>Preview</em></a></li>
                    <li><a href="#tab4"><em>Resources</em></a></li>
                    <li><a href="#tab5"><em>Wiki Syntax</em></a></li>
                </ul>
                <div class="yui-content">
                    <div><p><c:out value="${_content_1}" escapeXml="false" /></p></div>
                    <div><p><c:out value="${_content_2}" escapeXml="false"/></p></div>
                    <div><p><c:out value="${_content_3}" escapeXml="false"/></p></div>
                    <div><p><c:out value="${_content_4}" escapeXml="false" /></p></div>
                    <div><p><c:out value="${_content_5}" escapeXml="false" /></p></div>
                </div>
            </div>
        </stripes:layout-component>
    </stripes:layout-render>
</stripes:layout-definition>



